﻿using BLL;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ShoppingWebSite
{
    public partial class infoUpdate : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(Session["UserId"] == null)
            {
                Response.Redirect("homeWeb.aspx");
            }
            else
            {
                if (!IsPostBack)
                {
                    string sql = string.Format("select * from UserName where UId={0}", Session["UserId"].ToString());
                    DataTable dt = BLLAllOperation.BLL_GetDataTable(sql);
                    txtUserName.Text = dt.Rows[0]["UName"].ToString();
                    txtPwd.Text = dt.Rows[0]["UPwd"].ToString();
                    txtRealName.Text = dt.Rows[0]["URealName"].ToString();
                    txtTel.Text = dt.Rows[0]["UTel"].ToString();
                }
                
            }
        }

        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            string sql = string.Format("Update UserName set UPwd='{0}',URealName='{1}',UTel='{2}' where " +
                "UId={3}",txtPwd.Text.Trim(),txtRealName.Text.Trim(),txtTel.Text.Trim(),Session["UserId"].ToString());
            if (DBHelper.GetExecuteNonQuery(sql))
            {
                Response.Write("<script>alert('更新成功')</script>");
            }
            else
            {
                Response.Write("<script>alert('更新失败')</script>");
            }
        }
    }
}